package com.eliota.utils;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;

/**
 * @author M.G
 * @create 2023-03-21 16:29
 * @date 2023/3/21 16:29
 *
 * 代码生成器
 */
public class GeneratorUtil {

    private static String  sqlURL= "jdbc:mysql://localhost:3306/gew?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true";


    public  static void generator(){
        FastAutoGenerator.create(sqlURL, "root", "gh")
                .globalConfig(builder -> {
                    builder.author("MG") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir("D:\\JAVA\\newWorkpalce\\eliota\\workplace\\spring-vue\\springboot\\src\\main\\java\\"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.eliota") // 设置父包名
                            .moduleName("") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "D:\\JAVA\\newWorkpalce\\eliota\\workplace\\spring-vue\\springboot\\src\\main\\resources\\mapper\\")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder().enableLombok();
                    builder.mapperBuilder().enableMapperAnnotation();
                    builder.controllerBuilder().enableRestStyle()
                                    .enableHyphenStyle();
                    builder.addInclude("t_dict") // 设置需要生成的表名
                            .addTablePrefix("t_", "c_"); // 设置过滤表前缀
                })
                //.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }


    public static void main(String[] args) {
        generator();
    }

}
